import 'dart:io';

import 'package:flutter_base_plugin/flutter_base_plugin.dart';
import 'package:flutter_base_plugin_example/config/sp_key.dart';
import 'http_urls.dart';

class HttpConfigImpl extends IHttpConfig {
  @override
  BaseOptions configBaseOptions() {
    // TODO: implement configBaseOptions
    BaseOptions option = BaseOptions();
    option.baseUrl = HttpUrls.httpHost;
    option.contentType = Headers.jsonContentType;
    option.responseType = ResponseType.json;
    option.receiveDataWhenStatusError = false;
    option.connectTimeout = 30000;
    option.receiveTimeout = 3000;
    Map<String, dynamic> header = {
      "Authori-zation": "Bearer ${SpUtils.getString(SpKey.spAppToken)}",
    };
    option.headers = header;
    return option;
  }

  @override
  Map<String, dynamic> configOptionsHeaders() {
    // TODO: implement configOptionsHeaders
    Map<String, dynamic> header = {
      "x-token": SpUtils.getString(SpKey.spAppToken),
    };
    return header;
  }

  @override
  bool configHttps(X509Certificate cert, String host, int port) {
    // TODO: implement configHttps
    return false;
  }

  @override
  List<Interceptor>? configInterceptors() {
    // TODO: implement configInterceptors
    return [];
  }

  @override
  String configLoadingText() {
    // TODO: implement configLoadingText
    return "正在加载中···";
  }

  @override
  String getBaseUrl(String url) {
    // TODO: implement getBaseUrl
    return HttpUrls.httpHost;
  }

  @override
  bool isCancelableDialog() {
    // TODO: implement isCancelableDialog
    return false;
  }

  @override
  bool isShowFailToast() {
    // TODO: implement isShowFailToast
    return true;
  }

  @override
  bool isShowLoading() {
    // TODO: implement isShowLoading
    return true;
  }

  @override
  Future<void> showFailToast(HttpErrorBean errorBean) {
    // TODO: implement showFailToast
    return ToastUtils.show(errorBean.message);
  }

  @override
  int configInitPageIndex() {
    // TODO: implement configInitPageIndex
    return 1;
  }

  @override
  int configPageSize() {
    // TODO: implement configPageSize
    return 10;
  }
}
